const jwt = require('jsonwebtoken')
const config = require('../config/common_cfg')
module.exports = async (ctx, next) => {
    const token = ctx.get('token')
    console.log(token)
    if(token){
        try{
            const decode = jwt.verify(token, config.jwt.secret)
            console.log(decode)
            // let deadLine = new Date()/1000
            // if(deadLine <= decode.exp){
            //     await next()
            // }else {
            //     ctx.throw(401,'token expired')
            // }
        }catch (err) {
            console.log('wcao1')
            ctx.throw(401,'verify token failed')
        }
    }else {
        ctx.throw(401,'no token')
    }
    await next()
}
